package com.example.chessapp;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class ScoreActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_score);

        TextView red = findViewById(R.id.red);
        String red_str = red.getText().toString();

        TextView blue = findViewById(R.id.blue);
        String blue_str = blue.getText().toString();

        Button b_1 = findViewById(R.id.blue_1);
        Button b_2 = findViewById(R.id.blue_2);
        Button b_3 = findViewById(R.id.blue_3);
        Button r_1 = findViewById(R.id.red_1);
        Button r_2 = findViewById(R.id.red_2);
        Button r_3 = findViewById(R.id.red_3);
        Button begin = findViewById(R.id.new_game);
        Button over = findViewById(R.id.over_game);


    }

    public void be(View v){
        TextView blue = findViewById(R.id.blue);
        blue.setText("0");
        TextView red = findViewById(R.id.red);
        red.setText("0");
        AlertDialog.Builder builder = new AlertDialog.Builder(ScoreActivity.this);
        builder.setTitle("新的开始");//biaoti
        builder.setMessage("已重置历史记录");//neirong
        builder.setPositiveButton("确定",null);
        builder.show();
    }

    public void ov(View v){
        TextView blue = findViewById(R.id.blue);
        String blue_str = blue.getText().toString();
        int a = Integer.parseInt(blue_str);

        TextView red = findViewById(R.id.red);
        String red_str = red.getText().toString();
        int b = Integer.parseInt(red_str);

        String str;

        if(a > b) {
            str = "蓝队胜利！";
        }else if(a == b){
            str = "两队平局！";
        }else{
            str = "红队胜利！";
        }

        AlertDialog.Builder builder = new AlertDialog.Builder(ScoreActivity.this);
        builder.setTitle("比赛结束！");//biaoti
        builder.setMessage(str);//neirong
        builder.setPositiveButton("确定",null);
        builder.show();
    }


    public void blue_1(View v){
        TextView blue = findViewById(R.id.blue);
        String blue_str = blue.getText().toString();
        int a = Integer.parseInt(blue_str);
        int b = a + 1;
        String c = String.valueOf(b);
        blue.setText(c);
    }

    public void blue_2(View v){
        TextView blue = findViewById(R.id.blue);
        String blue_str = blue.getText().toString();
        int a = Integer.parseInt(blue_str);
        int b = a + 2;
        String c = String.valueOf(b);
        blue.setText(c);
    }

    public void blue_3(View v){
        TextView blue = findViewById(R.id.blue);
        String blue_str = blue.getText().toString();
        int a = Integer.parseInt(blue_str);
        int b = a + 3;
        String c = String.valueOf(b);
        blue.setText(c);
    }

    public void red_1(View v){
        TextView red = findViewById(R.id.red);
        String red_str = red.getText().toString();
        int a = Integer.parseInt(red_str);
        int b = a + 1;
        String c = String.valueOf(b);
        red.setText(c);
    }

    public void red_2(View v){
        TextView red = findViewById(R.id.red);
        String red_str = red.getText().toString();
        int a = Integer.parseInt(red_str);
        int b = a + 2;
        String c = String.valueOf(b);
        red.setText(c);
    }

    public void red_3(View v){
        TextView red = findViewById(R.id.red);
        String red_str = red.getText().toString();
        int a = Integer.parseInt(red_str);
        int b = a + 3;
        String c = String.valueOf(b);
        red.setText(c);
    }

    public void Scoreback(View V) {
        Intent intent = new Intent(ScoreActivity.this, MainActivity.class);
        startActivity(intent);
    }
}

